package controller;


import entity.Patient;
import entity.Register;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.RegisterService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/register")
@Scope("prototype")
public class RegisterController {

    @Resource(name = "registerService")
    RegisterService registerService;

    @RequestMapping("/getRegisterInfo")
    @ResponseBody
    Map<String,Object> GetRegisterAllInfo(Register register, int pageSize, int pageNumber, String name){
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("rStat",register.getrStat());
        map.put("rCode",register.getrCode());
        map.put("name",name);
        map.put("offset",(pageNumber-1)*pageSize);
        map.put("limit",pageSize);
        return registerService.GetRegisterInfo(map);
    }

    @RequestMapping("/AddQueryPatient")
    @ResponseBody
    Patient AddQueryPatient(String pName, String query){
       Patient patient= registerService.GetPatientByRegister(pName);
        if (patient!=null){
            return patient ;
        }
        return null;
    }

    @RequestMapping("/AddRegister")
    @ResponseBody
    String AddRegisterInfo(Patient patient, Register register, String pdId){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("patient",patient);
        map.put("register",register);
        map.put("PdId",pdId);
        registerService.AddRegister(map);
        return  null;
    }

}
